import * as THREE from 'three';
import CimEntity from './CimEntity.js'
class CimBuilding extends CimEntity {
    constructor(config) {
        super(config)
        this.model_3d = config.model_3d
        this.lodSetting = config.lodSetting
        this.floors = config.floorList
    }

    create3DEntity() {
        let entity = new THREE.LOD()
        let that = this
        //console.log(that.position);
        this.model_3d.forEach(model => {
            entity.addLevel(this.loadModel("/testModel/" + model.model_url +`?timestamp=${timestamp}`, "/testModel/" + model.material_url || this.defaultMaterial, { x: 0, y: 0, z: 0 }, that.rotation || { x: 0, y: 0, z: 0 }), this.lodSetting[model.lod].distance)
        });
        this.threeModel = entity
        //console.log('建筑物lod模型',entity);
        return entity
    }

    //从数据层面删除实体
    deleteEntity() {
        //查找other节点
        let other = this.parent
        //获取顶层节点
        while (!other.scene_id) {
            other = other.parent
        }


        while (this.lod != other.lod) {
            other = other.children.find(child =>
                child instanceof CimOther
            )
        }

        //从父节点删除掉这个实体孩子
        const index = this.parent.children.indexOf(this)
        if (index != -1) {
            this.parent.children.splice(index, 1)
        }
        //移除其他内容
        this.parent = null
        this.threeModel=null
    }


}

export default CimBuilding